import 'package:practice/generated/json/base/json_convert_content.dart';

class BaseResult<T> extends Object {

  int? errcode;
  String? errmsg;
  Map<String, dynamic>? results;

  List<dynamic>? resultsList;

  BaseResult({this.errcode, this.errmsg, this.results, this.resultsList});

  BaseResult.fromJson(Map<String, dynamic> json) {
    errcode = json['code'];
    errmsg = json['msg'];
    results = json['businessData']?? json["data"];
  }

  BaseResult.fromJsonList(Map<String, dynamic> jsonList) {
    errcode = jsonList['code'];
    errmsg = jsonList['msg'];
    resultsList = jsonList['businessData'] ??jsonList["data"];
  }
  BaseResult.fromJsonRowList(Map<String, dynamic> jsonRowList){
    errcode = jsonRowList['code'];
    errmsg = jsonRowList['msg'];
    resultsList = jsonRowList["data"]['rows'];
  }

  /// 获取results对象  映射到data中
  T getObject<T>() {
    return JsonConvert.fromJsonAsT<T>(results);
  }

  /// 获取results数组
  List<T> getList<T>() {
    var list = <T>[];
    if (resultsList != null) {
      for (var v in resultsList!) {
        list.add(JsonConvert.fromJsonAsT<T>(v));
      }
    }
    return list;
  }
}
